#include <iostream>

#include "cppTutorCommand.h"

#include "cppTutorLog.h"
extern CcppTutorLog Log;

using namespace std;

// Receiver : StockTrade
StockTrade :: StockTrade() {
    Log << "ENTER : StockTrade :: StockTrade()" << endl;
    Log << "EXIT  : StockTrade :: StockTrade()" << endl;
}

StockTrade :: ~StockTrade() {
    Log << "ENTER : StockTrade :: StockTrade()" << endl;
    Log << "EXIT  : StockTrade :: StockTrade()" << endl;
}

void StockTrade :: buy () {
    Log << "ENTER : StockTrade :: buy()" << endl;
    cout << "Buy stock" << endl; 
    Log << "EXIT  : StockTrade :: buy() [" << 0 << " : " << __LINE__ << "]"<< endl;
}

void StockTrade :: sell() { 
    Log << "ENTER : StockTrade :: sell()" << endl;
    cout << "Sell stock" << endl; 
    Log << "EXIT  : StockTrade :: sell() [" << 0 << " : " << __LINE__ << "]"<< endl;
}

// Concrete command 1 : BuyOrder
BuyOrder :: BuyOrder(StockTrade* stock) {
    Log << "ENTER : BuyOrder :: BuyOrder()" << endl;
    this->stock = stock;
    Log << "EXIT  : BuyOrder :: BuyOrder()" << endl;
}

BuyOrder :: ~BuyOrder () {
    Log << "ENTER : BuyOrder :: ~BuyOrder()" << endl;
    Log << "EXIT  : BuyOrder :: ~BuyOrder()" << endl;
}

void BuyOrder :: execute() {
    Log << "ENTER : StockTrade :: execute()" << endl;
    stock->buy();
    Log << "EXIT  : StockTrade :: execute() [" << 0 << " : " << __LINE__ << "]"<< endl;
}

// Concrete command 2 : SellOrder
SellOrder :: SellOrder(StockTrade* stock) {
    Log << "ENTER : SellOrder :: SellOrder()" << endl;
    this->stock = stock;
    Log << "EXIT  : SellOrder :: SellOrder()" << endl;
}

SellOrder :: ~SellOrder () {
    Log << "ENTER : SellOrder :: ~SellOrder()" << endl;
    Log << "EXIT  : SellOrder :: ~SellOrder()" << endl;
}
void SellOrder :: execute() {
    Log << "ENTER : SellOrder :: execute()" << endl;
    stock->sell();
    Log << "EXIT  : StockTrade :: execute() [" << 0 << " : " << __LINE__ << "]"<< endl;
}

// Invoker : StockAgent
StockAgent :: StockAgent () {
    Log << "ENTER : StockAgent :: StockAgent()" << endl;
    Log << "EXIT  : StockAgent :: StockAgent()" << endl;
}

StockAgent :: ~StockAgent () {
    Log << "ENTER : StockAgent :: ~StockAgent()" << endl;
    Log << "EXIT  : StockAgent :: ~StockAgent()" << endl;
}

void StockAgent :: order( Command* command ) {
    Log << "ENTER : StockAgent :: order()" << endl;
    commandList.push_back(command);
    command->execute();
    Log << "EXIT  : StockAgent :: order() [" << 0 << " : " << __LINE__ << "]"<< endl;
}